package com.iyao_app.adapter;

import android.net.Uri;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.backends.pipeline.PipelineDraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.iyao_app.R;
import com.iyao_app.util.ResourcesUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者 :  胡家兵
 * 时间 :  2017/12/11.
 */

public class OnlyPictureAdapter extends BaseQuickAdapter<String, OnlyPictureAdapter.ViewHolder> {


    public OnlyPictureAdapter(@Nullable List<String> data) {
        super(R.layout.item_picture_dengbi, data);
    }


    @Override
    protected void convert(ViewHolder helper, String item) {


        try {
            Uri uri = Uri.parse(item);
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                    .setResizeOptions(new ResizeOptions((int) ResourcesUtils.getDimension(R.dimen.x195), (int) ResourcesUtils.getDimension(R.dimen.x195)))
                    .build();
            PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                    .setOldController(helper.mSdvPhoto.getController())
                    .setImageRequest(request)
                    .build();
            helper.mSdvPhoto.setController(controller);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class ViewHolder extends BaseViewHolder {
        @BindView(R.id.sdv_photo)
        SimpleDraweeView mSdvPhoto;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
